package com.loy;

import com.loy.entity.HelloProto;
import com.loy.entity.HelloServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class GrpcClient2 {

    public static void main(String[] args) {
        // 1. 创建和服务器端进行通信的管道
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("localhost", 9000).usePlaintext().build();
        // 2.获得代理对象 xx stub
        HelloServiceGrpc.HelloServiceBlockingStub helloServiceBlockingStub = HelloServiceGrpc.newBlockingStub(managedChannel);
        // 3. 完成rpc的调用了
        // 3.1 准备发送给服务器端的参数
        HelloProto.HelloRequest1.Builder builder = HelloProto.HelloRequest1.newBuilder();
        builder.addName("sunshuai");
        builder.addName("sunshuai1");
        builder.addName("sunshuai12");
        HelloProto.HelloRequest1 helloRequest = builder.build();

        // 调用远程方法，获取返回值
        HelloProto.HelloResponse1 helloResponse = helloServiceBlockingStub.hello1(helloRequest);
        String result = helloResponse.getResult();
        System.out.println("result  = " + result);
    }
}
